package com.shop.cereshop.business.service.shop.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.cereshop.business.dao.shop.CereShopSkuDAO;
import com.shop.cereshop.business.dao.shop.CereShopSkuNameDAO;
import com.shop.cereshop.business.service.shop.CereShopSkuNameService;
import com.shop.cereshop.business.service.shop.CereShopSkuService;
import com.shop.cereshop.commons.domain.shop.CereShopSku;
import com.shop.cereshop.commons.domain.shop.CereShopSkuName;
import com.shop.cereshop.commons.domain.shop.bo.CereShopSkuNameBo;
import com.shop.cereshop.commons.domain.shop.vo.CereShopSkuNameVo;
import org.apache.commons.lang3.ObjectUtils;
import org.assertj.core.util.Lists;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CereShopSkuNameServiceImpl extends ServiceImpl<CereShopSkuNameDAO, CereShopSkuName> implements CereShopSkuNameService {
    @Override
    public List<CereShopSkuNameVo> queryList(CereShopSkuNameBo bo) {
        List<CereShopSkuName> list = list(build(bo));
        if (CollectionUtil.isNotEmpty(list)){
           return convert(list);
        }
        return null;
    }

    @Override
    public LambdaQueryWrapper<CereShopSkuName> build(CereShopSkuNameBo bo) {
        LambdaQueryWrapper<CereShopSkuName> q1 = new LambdaQueryWrapper<>();
        q1.eq(ObjectUtil.isNotNull(bo.getSkuId()),CereShopSkuName::getSkuId,bo.getSkuId());
        return q1;
    }

    @Override
    public CereShopSkuNameVo convert(CereShopSkuName cereShopSku) {
        CereShopSkuNameVo vo = new CereShopSkuNameVo();
        BeanUtils.copyProperties(cereShopSku,vo);
        return vo;
    }

    @Override
    public List<CereShopSkuNameVo> convert(List<CereShopSkuName> cereShopSkuList) {
        List<CereShopSkuNameVo> vos = Lists.newArrayList();
        for (CereShopSkuName cereShopSkuName : cereShopSkuList) {
            vos.add(convert(cereShopSkuName));
        }
        return vos;
    }
}
